<template>
    <div class="photolist">
        <!-- 顶部滑动条 -->
       <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in classify" :key="item.id" @tap="getPhotoListByCateId(item.id)">
                        {{ item.title }}
                    </a>
                </div>
            </div>
        </div>
        <!-- 图片列表 -->
        <ul class="photolist">
            <routerLink tag="li" :to="'/home/photolist/photoinfo/'+item.id" v-for="(item, index) in imglist" :key="index">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1>{{ item.title }}</h1>
                    <p>{{ item.abstarct }}</p>
                </div>
            </routerLink>
        </ul>
    </div>

</template>

<script>
import mui from '../../icon/mui/js/mui.min.js'

    export default {
        data() {
            return {
                classify: [],
                imglist: [],

            }
        },
        methods: {
            getAllClassify(){
                var url = "https://www.fastmock.site/mock/3bcb60e708abec194c722ac5464b28d8/VueApp/getimgclass"
                this.$http.get(url).then(res=>{
                    if(res.status == 200){
                        var all = {
                            id: 0,
                            title: "全部"
                        }
                        this.classify = res.data.classify
                        this.classify.unshift(all)
                    }
                })
            },
            getPhotoListByCateId(cateId){
                var url = "https://www.fastmock.site/mock/3bcb60e708abec194c722ac5464b28d8/VueApp/getimginfo"
                this.$http.get(url).then(res=>{
                    if(res.status == 200){
                        this.imglist = []
                        this.imglist = res.data.imglist[cateId]
                    }
                })
            }
        },
        created() {
            this.getAllClassify()
            this.getPhotoListByCateId(0)
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 
            })
        },
    }
</script>

<style lang="scss" scoped>
*{
    touch-action: pan-y;
}
img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.photolist{
    li{
        position: relative;
        img{
            width: 96%;
            margin-left: 2%;
            box-shadow: 0 0 10px gray;
            border: 4px solid black;
        }
        .info{
            width: 96%;
            margin-left: 2%;
            position: absolute;
            bottom: 8px;
            background-color: rgba(117, 117, 117, 0.363);
            border-left: 4px solid black;
            border-right: 4px solid black;
            // overflow: hidden;
            h1{
                font-size: 18px;
                font-weight: bold;
                color: wheat;
                padding-left: 5px;
            }
            p{
                color: #fff;
                font-size: 5px;
                padding: 0 5px;
                text-align: justify;
                line-height: 2.8em;
            }
        }
    }
}
</style>